package com.gemme.gemme.util;

import android.text.TextUtils;

import java.math.BigDecimal;

/**
 * @Author: yangcheng
 * @CreateDate: 2020/8/11 10:42
 */
public class StrUtil {
    public static final String noNUll(Object str){
        String s = "";
        try {
            if(str instanceof String)
            s = (String)str;
            if("null".equals(str)){
                s = "";
            }
            if("NULL".equals(str)){
                s = "";
            }
        }catch (Exception e){

        }

        return s;
    }

    public static final boolean isNUll(Object str){
        boolean isnull = false;
        try {
            return TextUtils.isEmpty(noNUll(str));
        }catch (Exception e){

        }

        return isnull;
    }

    public static Long toLong(Object obj){
        Long longStr = null;
        try {
            longStr = new Long(noNUll(obj));
        }catch (Exception e){

        }

        return longStr;

    }

    public static Double toDouble(Object obj){
        Double longStr = null;
        try {
            longStr = new Double(noNUll(obj));
        }catch (Exception e){

        }

        return longStr;

    }

//    (BigDecimal)obj

    public static BigDecimal toBigDecimal(Object obj){
        BigDecimal bigDecimal = null;
        try {
            bigDecimal = (BigDecimal)obj;
        }catch (Exception e){

        }
        return bigDecimal;

    }
    public static Integer toINt(Object obj){
        Integer longStr = 0;
        try {
            longStr = new Integer((Integer) obj);
        }catch (Exception e){

        }

        return longStr;

    }

    public static String getTime(Object obj){
        String str = "";
       try {
           String s = noNUll(obj);
           str = s.substring(0,10);
       }catch (Exception e){

       }

       return str;

    }

    public static String getTitle(Object obj){
        String str = "";
        try {
            String s = noNUll(obj);
            if(s.length() >= 14){
                str = s.substring(0,14);
            }else{
                str = s;
            }

        }catch (Exception e){

        }

        return str;

    }


}
